home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Demo / tkinter / matt / window-creation-w-location.py < prev   
Encoding:
Python Source  |  2000-06-23  |  1.2 KB  |  46 lines

  1. from Tkinter import *
  2.  
  3. import sys
  4. ##sys.path.append("/users/mjc4y/projects/python/tkinter/utils")
  5. ##from TkinterUtils  import *
  6.  
  7. # this shows how to create a new window with a button in it that
  8. # can create new windows
  9.  
  10. class QuitButton(Button):
  11.     def __init__(self, master, *args, **kwargs):
  12.         if not kwargs.has_key("text"):
  13.             kwargs["text"] = "QUIT"
  14.         if not kwargs.has_key("command"):
  15.             kwargs["command"] = master.quit
  16.         apply(Button.__init__, (self, master) + args, kwargs)
  17.  
  18. class Test(Frame):
  19.     def makeWindow(self, *args):
  20.     fred = Toplevel()
  21.  
  22.     fred.label = Canvas (fred, width="2i", height="2i")
  23.  
  24.     fred.label.create_line("0", "0", "2i", "2i")
  25.     fred.label.create_line("0", "2i", "2i", "0")
  26.     fred.label.pack()
  27.  
  28.     ##centerWindow(fred, self.master)
  29.  
  30.     def createWidgets(self):
  31.     self.QUIT = QuitButton(self)
  32.     self.QUIT.pack(side=LEFT, fill=BOTH)
  33.  
  34.     self.makeWindow = Button(self, text='Make a New Window',
  35.                  width=50, height=20,
  36.                  command=self.makeWindow)
  37.     self.makeWindow.pack(side=LEFT)
  38.  
  39.     def __init__(self, master=None):
  40.     Frame.__init__(self, master)
  41.     Pack.config(self)
  42.     self.createWidgets()
  43.  
  44. test = Test()
  45. test.mainloop()
  46.